#version 410 core

// Declare all the semantics
#define ATTR_POSITION	0
#define ATTR_NORMAL		1
#define ATTR_COLOR		2

#define VERT_POSITION	0
#define VERT_NORMAL		1
#define VERT_COLOR		2
#define VERT_INSTANCE	3

#define FRAG_COLOR		0

uniform mat4 ModelView;
uniform mat4 ModelViewProj;

layout(location = ATTR_POSITION) in vec3 Position;

layout(location = VERT_INSTANCE) out float vDepth;

vec3 randomize(vec3 pos)
{
	vec3 random = 0.08f * vec3(
		sin(pos.x + pos.y * 2.0f + pos.z * 4.0f),
		sin(pos.x + pos.y * 8.0f + pos.z * 16.0f),
		cos(pos.x + pos.y * 3.0f + pos.z * 6.0f));

	return random + Position;
}

void main()
{
	vec3 randomizedPos = randomize(Position);
	gl_Position = ModelViewProj * vec4(randomizedPos, 1.0f);
	
	vDepth = length((ModelView * vec4(randomizedPos, 1.0f)).xyz);
}
